//
//  WCG_O_TableViewCell.m
//  Project_B
//
//  Created by 黑黑 on 15/11/24.
//  Copyright © 2015年 Atom_Wang. All rights reserved.
//

#import "WCG_O_TableViewCell.h"
#import "WCG_O_CollectionViewCell.h"
@interface WCG_O_TableViewCell () <UICollectionViewDataSource, UICollectionViewDelegate>

@property (nonatomic, retain) UICollectionView *collectionView;
@property (nonatomic, retain) UICollectionViewFlowLayout *layout;

@end

@implementation WCG_O_TableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.layout = [[UICollectionViewFlowLayout alloc] init];
        self.layout.minimumInteritemSpacing = 0;
        self.layout.minimumLineSpacing = 0;
        self.collectionView = [[UICollectionView alloc] initWithFrame:self.contentView.frame collectionViewLayout:self.layout];
        self.collectionView.backgroundColor = [UIColor clearColor];
        self.collectionView.scrollsToTop = NO;
        self.collectionView.delegate = self;
        self.collectionView.dataSource = self;
        [self.contentView addSubview:self.collectionView];
        [self.collectionView registerClass:[WCG_O_CollectionViewCell class] forCellWithReuseIdentifier:@"collectionView"];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.layout.itemSize = CGSizeMake(self.contentView.frame.size.width / 2, self.contentView.frame.size.height / 2);
    self.collectionView.frame = self.contentView.frame;
    [self.collectionView reloadData];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.specialArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    WCG_O_CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"collectionView" forIndexPath:indexPath];
    cell.specialModel = self.specialArr[indexPath.item];
    [cell setNeedsDisplay];
    return cell;
}

// 代理人执行协议方法
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [self.delegate pushCollectionViewWith:[self.specialArr[indexPath.item] special_id]];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
